<template>
  <div class="app-container">
    <el-form ref="form" :model="form" label-width="120px">
      <el-form-item label="日期" prop="up_time" required>
        <el-date-picker v-model="form.up_time" type="date" value-format="yyyy-MM-dd hh:mm:ss" editable placeholder="选择日期" style="width: 200px" />
      </el-form-item>

      <el-form-item label="内容" prop="content" required>
        <el-input type="textarea" placeholder="请填写内容" v-model="form.content" rows="6"></el-input>
      </el-form-item>


      <el-form-item>
        <el-button type="primary" @click="onSubmit">提交</el-button>
        <el-button @click="$router.push({path:'/update_log/index'})">返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import api from '@/api/update_log'
export default {
  components: {},
  data() {
    return {
      form: {
        id: 0,
        up_time: null,
        content: ''
      }
    }
  },

  mounted() {
    if (this.$route.query.hasOwnProperty('id')) {
      this.getData(this.$route.query.id)
    }
  },

  methods: {
    getData(id) {
      api.info({ id: id }).then((res) => {
        this.form = res.data
      })
    },
    onSubmit() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          let req
          if (this.form.id > 0) {
            req = api.update(this.form)
          } else {
            req = api.create(this.form)
          }
          req.then((res) => {
            this.$message({
              type: 'success',
              message: res.msg,
              duration: 500,
              onClose: () => {
                this.$router.push({ path: '/update_log/index' })
              }
            })


          }).catch((error) => {

          })
        }
      });

    }
  }
}
</script>

<style scoped>
.line {
  text-align: center;
}

.editor-content {
  margin-top: 20px;
}

.article-textarea ::v-deep {

  textarea {
    padding-right: 40px;
    resize: none;
    border: none;
    border-radius: 0px;
    border-bottom: 1px solid #bfcbd9;
  }

}
</style>

